﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Lenovo.CFI.Common;
using Lenovo.CFI.Common.Sys;
using Lenovo.CFI.DAL.Sys;

namespace Lenovo.CFI.BLL.Sys
{
    public class TeamBl
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="enabled">NULL表示不限制</param>
        /// <param name="gddl">NULL表示不限制</param>
        /// <param name="manager">NULL表示不限制</param>
        /// <param name="vp">NULL表示不限制</param>
        /// <returns></returns>
        public List<Team> GetTeam(bool? enabled, bool? gddl, string manager, string vp)
        {
            return TeamDa.GetTeam(enabled, gddl, manager, vp);
        }

        public Team GetTeamByID(int id)
        {
            return TeamDa.GetTeamByID(id);
        }


        public void AddTeam(Team team)
        {
            if (team.GDDL)
            {
                if (String.IsNullOrEmpty(team.Manager) || String.IsNullOrEmpty(team.VP))
                {
                    throw new BusinessObjectLogicException("Please set Manager and VP!");
                }
            }
            else
            {
                team.Manager = null;
                team.VP = null;
            }
            team.UID = Guid.NewGuid();

            TeamDa.InsertTeam(team);
        }

        public void EditTeam(Team team)
        {
            if (team.GDDL)
            {
                if (String.IsNullOrEmpty(team.Manager) || String.IsNullOrEmpty(team.VP))
                {
                    throw new BusinessObjectLogicException("Please set Manager and VP!");
                }
            }
            else
            {
                team.Manager = null;
                team.VP = null;
            }

            TeamDa.UpdateTeam(team);
        }

    }
}
